package dao

import (
	"regexp"
	"user-server/basic/global"
)

func Create[T any](data *T) bool {
	if err := global.DB.Create(&data).Error; err != nil {
		return false
	}
	return true
}
func GetOneByTel[T any](tel string, data *T) bool {
	if err := global.DB.Where("tel = ?", tel).Find(&data).Error; err != nil {
		return false
	}
	return true
}
func Phone(phone string) bool {
	pattern := `^1[3-9]\d{9}$`
	compile, err := regexp.Compile(pattern)
	if err != nil {
		return false
	}
	return compile.MatchString(phone)
}
func Find[T any](data *T) bool {
	if err := global.DB.Find(&data).Error; err != nil {
		return false
	}
	return true
}
